package bingfa

import "fmt"

//这里一定要注意，一旦管道的任务结束了，就要立即将它关闭，若不关闭，就要一直等待数据传入造成一直阻塞
var chanIntJudge =make(chan int,8000)
var primeNum =make(chan int,2000)
var work=make(chan int,4)
var end =make(chan int,0)

func addJudgeInt()  {
	for i:=0;i<8000;i++{
		chanIntJudge<-i
	}
	close(chanIntJudge)
}
func judgePrimeNum(){
	for numflag:=range chanIntJudge{
		flag:=true
		for i:=2;i<numflag;i++{
			if numflag%i==0{
				flag=false
				break
			}
		}
		if flag{
			primeNum<-numflag
		}
	}
	work<-1
}
func printPrime(){
	for{
		num,exists:=<-primeNum
		if !exists{
			break
		}
		fmt.Println(num)
	}
	end<-1
}
func Test11(){
	go addJudgeInt()
	go judgePrimeNum()
	go judgePrimeNum()
	go judgePrimeNum()
	go judgePrimeNum()
	go printPrime()
	go func() {
		for{
			if len(work)==4{
				close(primeNum)
				break
			}
		}
	}()
	<-end
}